package cn.edu.swu.book;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/UpdateBook")
public class UpdateBookServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        int id=Integer.valueOf(req.getParameter("id"));
        String name = req.getParameter("name");
        String author = req.getParameter("author");
        String content = req.getParameter("content");
        Float price = Float.valueOf(req.getParameter("price"));

        BOOK book =new BOOK(id,name,author,content,price);

        try{
            bookApplication.getInstance().updateBook(book);
            resp.sendRedirect("./index-simple");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
